﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using User_Interface_Design.DAO;
using User_Interface_Design.DTO;

namespace User_Interface_Design
{
    public partial class TraCuuThongTinKhachHang : Form
    {
        public TraCuuThongTinKhachHang()
        {
            InitializeComponent();
            dateTimePicker1.CustomFormat = " ";
            dateTimePicker1.Format = DateTimePickerFormat.Custom; 
            groupBox1.Enabled = false;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<KhachHang> kq = new List<KhachHang>();

            if (checkBox1.Checked)
            {
                if (dateTimePicker1.Format != DateTimePickerFormat.Short)
                    kq = DataAccess.TimKiemKhachHang(textBox1.Text, comboBox1.Text, "", textBox4.Text, textBox5.Text);
                else
                    kq = DataAccess.TimKiemKhachHang(textBox1.Text, comboBox1.Text, dateTimePicker1.Value.ToString(), textBox4.Text, textBox5.Text);
            }
            else
                kq = DataAccess.TimKiemKhachHang(textBox1.Text);

            foreach (KhachHang kh in kq)
            {
                DataGridViewRow r = new DataGridViewRow();
                r.CreateCells(dataGridView1);
                r.Cells[0].Value = kh.HoTen;
                r.Cells[1].Value = kh.CMND;
                r.Cells[2].Value = kh.GioiTinh;
                r.Cells[3].Value = kh.NgaySinh;
                r.Cells[4].Value = kh.DiaChi;
                r.Cells[5].Value = kh.DienThoai;

                dataGridView1.Rows.Add(r);
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            groupBox1.Enabled = true;
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            dateTimePicker1.Format = DateTimePickerFormat.Short;
        }

    }
}
